package com.quzhi.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.quzhi.common.code.Code;
import com.quzhi.common.Result;
import com.quzhi.sys.entity.GoodsSign;
import com.quzhi.sys.mapper.GoodsSignMapper;
import com.quzhi.sys.service.IGoodsSignService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Xibing
 * @since 2024-07-09
 */
@Service
public class GoodsSignServiceImpl extends ServiceImpl<GoodsSignMapper, GoodsSign> implements IGoodsSignService {

    public Result<?> addGoodsSignService(GoodsSign goodsSign) {
        // 查询所有备注，如果该手机号存在则提示该手机号备注已存在
        LambdaQueryWrapper<GoodsSign> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GoodsSign::getNumber, goodsSign.getNumber());

        GoodsSign sing = this.baseMapper.selectOne(wrapper);
        if(sing != null) return Result.fail(Code.FAIL_CODE, "该订单备注已经添加过了");

        // 设置ID 创建时间，更新时间
        goodsSign.setId(UUID.randomUUID().toString());
        goodsSign.setCreateTime(LocalDateTime.now());
        goodsSign.setUpdateTime(LocalDateTime.now());
        this.baseMapper.insert(goodsSign);
        return Result.success("添加成功");
    }

    @Override
    public Result<?> updateGoodsSignService(GoodsSign goodsSign) {
        // 查询所有备注，如果该手机号存在则提示该手机号备注已存在
        goodsSign.setUpdateTime(LocalDateTime.now());
        this.baseMapper.updateById(goodsSign);

        return Result.success("更新成功");
    }

    @Override
    public List<GoodsSign> getGoodsSignServiceNeedStatus(Boolean status) {
        LambdaQueryWrapper<GoodsSign> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GoodsSign::getStatus, status);

        return this.baseMapper.selectList(wrapper);
    }


}
